<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"sekla.cn","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="LRU算法实现​    为了提高内存的利用率，提高交换效率，LRU算法是应用最广泛的内存页面置换算法。 假设分配给进程的页块为3，页面访问序列长度为20。采用数组结构实现，随机产生页面序列。数组运用计数器维护：">
<meta property="og:type" content="article">
<meta property="og:title" content="LRU算法&amp;&amp;首次适应分配及位图维护内存分配实现">
<meta property="og:url" content="http://sekla.cn/2021/12/15/os-schoollab-7/index.html">
<meta property="og:site_name" content="Sekla&#39;s Blog">
<meta property="og:description" content="LRU算法实现​    为了提高内存的利用率，提高交换效率，LRU算法是应用最广泛的内存页面置换算法。 假设分配给进程的页块为3，页面访问序列长度为20。采用数组结构实现，随机产生页面序列。数组运用计数器维护：">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s2.loli.net/2021/12/14/uCUNvTFJ4OqSWyz.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/14/hkmIf9lCDLu7yo8.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/14/ra7JxbD2SA94zKX.png">
<meta property="og:image" content="https://s2.loli.net/2021/12/14/u3GLBMVt6xNe9Xh.png">
<meta property="article:published_time" content="2021-12-15T04:30:00.000Z">
<meta property="article:modified_time" content="2021-12-15T03:19:25.727Z">
<meta property="article:author" content="Sekla">
<meta property="article:tag" content="C++">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s2.loli.net/2021/12/14/uCUNvTFJ4OqSWyz.png">

<link rel="canonical" href="http://sekla.cn/2021/12/15/os-schoollab-7/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>LRU算法&&首次适应分配及位图维护内存分配实现 | Sekla's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  <script type="text/javascript" src="/js/my_js/clicklove.js"></script>
<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Sekla's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Keep Learning Keep Doing</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">100</span></a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://sekla.cn/2021/12/15/os-schoollab-7/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Sekla">
      <meta itemprop="description" content="Sekla">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Sekla's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LRU算法&&首次适应分配及位图维护内存分配实现
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-12-15 12:30:00 / 修改时间：11:19:25" itemprop="dateCreated datePublished" datetime="2021-12-15T12:30:00+08:00">2021-12-15</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" itemprop="url" rel="index"><span itemprop="name">操作系统</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>11k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>10 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="LRU算法实现"><a href="#LRU算法实现" class="headerlink" title="LRU算法实现"></a>LRU算法实现</h2><p>​    为了提高内存的利用率，提高交换效率，LRU算法是应用最广泛的内存页面置换算法。</p>
<p>假设分配给进程的页块为3，页面访问序列长度为20。采用数组结构实现，随机产生页面序列。数组运用计数器维护：</p>
<p><img src="https://s2.loli.net/2021/12/14/uCUNvTFJ4OqSWyz.png" alt="image-20211214191453826"></p>
<a id="more"></a>

<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"> <span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"> <span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"> <span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> checkLength = <span class="number">20</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> pageFrame = <span class="number">3</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> miss = <span class="number">0</span>;</span><br><span class="line"><span class="function"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; <span class="title">pf</span><span class="params">(<span class="number">3</span>,<span class="number">0</span>)</span></span>;</span><br><span class="line"><span class="function"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; <span class="title">referString</span><span class="params">(<span class="number">20</span>)</span></span>;</span><br><span class="line"><span class="function"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; <span class="title">timeCnt</span><span class="params">(<span class="number">3</span>,<span class="number">0</span>)</span></span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;输入长度为20的引用串&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;<span class="number">20</span>;i++)</span><br><span class="line">        <span class="built_in">cin</span> &gt;&gt; referString[i];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">LRU</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> cnt=<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">int</span> replace=<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">bool</span> flag=<span class="literal">false</span>;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;开始进行LRU算法&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">while</span>(cnt&lt;<span class="number">20</span>)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;--------------------------&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;第&quot;</span> &lt;&lt; cnt+<span class="number">1</span> &lt;&lt; <span class="string">&quot;次检索&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;<span class="number">3</span>;i++)&#123;</span><br><span class="line">            <span class="keyword">if</span>(pf[i]==referString[cnt])&#123;</span><br><span class="line">                <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;访问帧&quot;</span> &lt;&lt; referString[cnt] &lt;&lt; <span class="string">&quot;命中&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">                timeCnt[i] = cnt;</span><br><span class="line">                flag=<span class="literal">true</span>;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(flag==<span class="literal">false</span>)&#123;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;访问帧&quot;</span> &lt;&lt; referString[cnt] &lt;&lt; <span class="string">&quot;缺页&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;<span class="number">3</span>;i++)&#123;</span><br><span class="line">                <span class="keyword">if</span>(timeCnt[i]&lt;timeCnt[replace])</span><br><span class="line">                    replace=i;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;页帧号&quot;</span> &lt;&lt; pf[replace] &lt;&lt; <span class="string">&quot;被替换&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            pf[replace] = referString[cnt];</span><br><span class="line">            timeCnt[replace] = cnt+<span class="number">1</span>;</span><br><span class="line">            miss++;</span><br><span class="line">            replace=<span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        flag=<span class="literal">false</span>;</span><br><span class="line">        cnt ++;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="主存储空间的分配与回收"><a href="#主存储空间的分配与回收" class="headerlink" title="主存储空间的分配与回收"></a>主存储空间的分配与回收</h2><p>​    本实验要求模拟在两种存储管理方式下的主存分配和回收。</p>
<h3 id="可变分区管理下采用最先适应算法实现主存分配和回收"><a href="#可变分区管理下采用最先适应算法实现主存分配和回收" class="headerlink" title="可变分区管理下采用最先适应算法实现主存分配和回收"></a>可变分区管理下采用最先适应算法实现主存分配和回收</h3><p>可变分区方式是按作业需要的主存空间大小来分割分区的。当要装入一个作业时，根据作业需要的主存量查看是否有足够的空闲空间，若有，则按需要量分割一个分区分配给该作业；若无，则作业不能装入。随着作业的装入、撤离，主存空间被分成许多个分区，有的分区被作业占用，而有的分区是空闲的。</p>
<p><img src="https://s2.loli.net/2021/12/14/hkmIf9lCDLu7yo8.png" alt="image-20211214201845460"></p>
<p>现有一个需要主存量为6K的作业4申请装入主存；然后作业3撤离；再作业2撤离。请你为它们进行主存分配和回收，把空闲区说明表的初值以及每次分配或回收后的变化显示出来或打印出来。</p>
<p>假设主存中已装入三个作业，且形成两个空闲区，确定空闲区说明表的初值。</p>
<p><img src="https://s2.loli.net/2021/12/14/ra7JxbD2SA94zKX.png" alt="image-20211214202039776"></p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> Block = <span class="number">3</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">freelist</span>&#123;</span></span><br><span class="line">    <span class="keyword">int</span> start;</span><br><span class="line">    <span class="keyword">int</span> size;</span><br><span class="line">    <span class="keyword">bool</span> valide;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">freelist freeList[Block]=&#123;&#123;<span class="number">14</span>,<span class="number">12</span>,<span class="number">1</span>&#125;,&#123;<span class="number">32</span>,<span class="number">96</span>,<span class="number">1</span>&#125;,&#123;<span class="number">128</span>,<span class="number">120</span>,<span class="number">0</span>&#125;&#125;;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">alloc</span><span class="params">(<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> i,flag=<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;Block;++i)&#123;</span><br><span class="line">        <span class="keyword">if</span>(freeList[i].valide==<span class="number">1</span>&amp;&amp;freeList[i].size&gt;n)&#123;</span><br><span class="line">            freeList[i].start=freeList[i].start+n;</span><br><span class="line">            freeList[i].size=freeList[i].size-n;</span><br><span class="line">            <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(freeList[i].valide==<span class="number">1</span>&amp;&amp;freeList[i].size==n)&#123;</span><br><span class="line">            freeList[i].valide=<span class="number">0</span>;</span><br><span class="line">            <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">setFree</span><span class="params">(<span class="keyword">int</span> start,<span class="keyword">int</span> size)</span></span>&#123;</span><br><span class="line">    <span class="comment">//检查相邻空闲区</span></span><br><span class="line">    <span class="keyword">int</span> flag1=<span class="number">0</span>,flag2=<span class="number">0</span>,flag3=<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">int</span> i,j=<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;Block;i++)&#123;</span><br><span class="line">        <span class="keyword">if</span>(freeList[i].start==(start+size)&amp;&amp;freeList[i].valide==<span class="number">1</span>)&#123;</span><br><span class="line">            size=size+freeList[i].size;</span><br><span class="line">            flag1=<span class="number">1</span>;</span><br><span class="line">            <span class="keyword">for</span>(j=<span class="number">0</span>;j&lt;Block;j++)&#123;</span><br><span class="line">                <span class="keyword">if</span>(freeList[j].start+freeList[j].size==start&amp;&amp;freeList[j].valide==<span class="number">1</span>)&#123;</span><br><span class="line">                    freeList[i].valide=<span class="number">0</span>;</span><br><span class="line">                    freeList[i].start=freeList[Block<span class="number">-1</span>].start+freeList[Block<span class="number">-1</span>].size;</span><br><span class="line">                    freeList[i].size=<span class="number">120</span>;</span><br><span class="line">                    freeList[j].size=freeList[j].size+size; <span class="comment">///向上合并空闲区</span></span><br><span class="line">                    flag2=<span class="number">1</span>; <span class="comment">///回收区有上下邻空闲区</span></span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(flag2==<span class="number">0</span>)&#123;</span><br><span class="line">                freeList[i].start=start;</span><br><span class="line">                freeList[i].size=size;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//回收区无下邻空闲区，检查其是否有上邻空闲区</span></span><br><span class="line">    <span class="keyword">if</span>(flag1==<span class="number">0</span>)&#123;</span><br><span class="line">        <span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;Block;i++)&#123;</span><br><span class="line">            <span class="keyword">if</span>(freeList[i].start+freeList[i].size==start &amp;&amp; freeList[i].valide==<span class="number">1</span>)&#123;</span><br><span class="line">                freeList[i].size=freeList[i].size +size;</span><br><span class="line">                flag3=<span class="number">1</span>;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(flag3==<span class="number">0</span>)&#123;</span><br><span class="line">        <span class="keyword">for</span>(j=<span class="number">0</span>;j&lt;Block;j++)&#123;</span><br><span class="line">            <span class="keyword">if</span>(freeList[j].valide==<span class="number">0</span>)&#123;</span><br><span class="line">                freeList[j].start=start;</span><br><span class="line">                freeList[j].size=size;</span><br><span class="line">                freeList[j].valide=<span class="number">1</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">sort</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> i,j;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">freelist</span> <span class="title">fl</span>;</span></span><br><span class="line">    <span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;Block;i++) <span class="comment">//将空闲区按始地址顺序在表中排列</span></span><br><span class="line">        <span class="keyword">for</span>(j=<span class="number">0</span>;j&lt;Block<span class="number">-1</span>;j++)</span><br><span class="line">            <span class="keyword">if</span>(freeList[j].start&gt;freeList[j+<span class="number">1</span>].start)&#123;</span><br><span class="line">                fl=freeList[j];</span><br><span class="line">                freeList[j]=freeList[j+<span class="number">1</span>];</span><br><span class="line">                freeList[j+<span class="number">1</span>]=fl;</span><br><span class="line">            &#125;</span><br><span class="line">    <span class="keyword">for</span>(i=<span class="number">0</span>;i&lt;Block;i++) <span class="comment">///将空表目放在表后面</span></span><br><span class="line">        <span class="keyword">for</span>(j=<span class="number">0</span>;j&lt;Block<span class="number">-1</span>;j++)</span><br><span class="line">            <span class="keyword">if</span>(freeList[j].valide==<span class="number">0</span> &amp;&amp; freeList[j+<span class="number">1</span>].valide==<span class="number">1</span>)&#123;</span><br><span class="line">                fl=freeList[j];</span><br><span class="line">                freeList[j]=freeList[j+<span class="number">1</span>];</span><br><span class="line">                freeList[j+<span class="number">1</span>]=fl;</span><br><span class="line">            &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> i,flag;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;初始空闲分区表为&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    sort();</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;起始地址   长度    状态&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;Block;i++)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; freeList[i].start &lt;&lt; <span class="string">&quot;      &quot;</span> &lt;&lt; freeList[i].size&lt;&lt; <span class="string">&quot;       &quot;</span> &lt;&lt; freeList[i].valide &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;--------------------------&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="comment">//task4进入</span></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;主存量为6K的任务4装入主存&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    flag=alloc(<span class="number">6</span>);</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt;<span class="string">&quot;分配后分区表状态为&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;起始地址   长度    状态&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;Block;i++)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; freeList[i].start &lt;&lt; <span class="string">&quot;      &quot;</span> &lt;&lt; freeList[i].size&lt;&lt; <span class="string">&quot;       &quot;</span> &lt;&lt; freeList[i].valide &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(flag==<span class="number">0</span>) <span class="built_in">cout</span> &lt;&lt;<span class="string">&quot;无空闲内存可分配&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;--------------------------&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;起始地址   长度    状态&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">    <span class="comment">//task3离开</span></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;作业3撤离，起始地址10，大小4&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    setFree(<span class="number">10</span>,<span class="number">4</span>);</span><br><span class="line">    sort();</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt;<span class="string">&quot;作业3撤离后分区表状态为&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;Block;i++)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; freeList[i].start &lt;&lt; <span class="string">&quot;      &quot;</span> &lt;&lt; freeList[i].size&lt;&lt; <span class="string">&quot;       &quot;</span> &lt;&lt; freeList[i].valide &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;--------------------------&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="comment">//task2离开</span></span><br><span class="line">     <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;作业2撤离，起始地址26，大小6&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    setFree(<span class="number">26</span>,<span class="number">6</span>);</span><br><span class="line">    sort();</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt;<span class="string">&quot;作业2撤离后分区表状态为&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;起始地址   长度    状态&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;Block;i++)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; freeList[i].start &lt;&lt; <span class="string">&quot;      &quot;</span> &lt;&lt; freeList[i].size&lt;&lt; <span class="string">&quot;       &quot;</span> &lt;&lt; freeList[i].valide &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="位图维护内存"><a href="#位图维护内存" class="headerlink" title="位图维护内存"></a>位图维护内存</h3><p>分页式存储器把主存分成大小相等的若干块，作业的信息也按块的大小分页，作业装入主存时可把作业的信息按页分散存放在主存的空闲块中，为了说明主存中哪些块已经被占用，哪些块是尚未分配的空闲块，可用一张位图来指出。</p>
<p>假设某系统的主存被分成大小相等的64块，则位图可用8个字节来构成，另用一单元记录当前空闲块数。如果已有第0，1，4，5，6，9，11，13，24，31，共10个主存块被占用了，那么位图情况如下图：</p>
<p><img src="https://s2.loli.net/2021/12/14/u3GLBMVt6xNe9Xh.png" alt="image-20211214215949392"></p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bitset&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">BitMap</span>&#123;</span></span><br><span class="line">    <span class="built_in">bitset</span>&lt;64&gt; bitmap;</span><br><span class="line">    <span class="keyword">int</span> <span class="built_in">free</span>;</span><br><span class="line">&#125;bitMap;</span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">process</span>&#123;</span></span><br><span class="line">    <span class="keyword">int</span> num;</span><br><span class="line">    <span class="keyword">int</span> size;</span><br><span class="line">    <span class="keyword">int</span> *pagetable;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">process</span> *<span class="title">pre</span>;</span></span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">process</span> *<span class="title">next</span>;</span></span><br><span class="line"> &#125;proc;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">void</span> <span class="title">creProc</span><span class="params">(proc *head)</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> tempNum;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;输入作业序号&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cin</span> &gt;&gt; tempNum;</span><br><span class="line">    proc *temp = <span class="keyword">new</span> proc();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(tempNum==<span class="number">0</span>)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;无法创建0号作业&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">delete</span> temp;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//遍历表</span></span><br><span class="line">    <span class="keyword">for</span>(temp=head;temp!=<span class="literal">nullptr</span>;temp=temp-&gt;next)&#123;</span><br><span class="line">        <span class="keyword">if</span>(temp-&gt;num==tempNum)&#123;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;已经有相同序号作业，返回&quot;</span> &lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">delete</span> temp;</span><br><span class="line"></span><br><span class="line">    proc *tp = <span class="keyword">new</span> proc();</span><br><span class="line">    tp-&gt;num=tempNum;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;输入作业大小&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cin</span> &gt;&gt; tp-&gt;size;</span><br><span class="line">    <span class="keyword">if</span>(tp-&gt;size&gt;bitMap.<span class="built_in">free</span>)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;没有足够内存分配&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">delete</span> tp;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//头插入节点</span></span><br><span class="line">    tp-&gt;next=head-&gt;next;</span><br><span class="line">    <span class="keyword">if</span>(head-&gt;next!=<span class="literal">nullptr</span>)</span><br><span class="line">        head-&gt;next-&gt;pre=tp;</span><br><span class="line">    tp-&gt;pre=head;</span><br><span class="line">    head-&gt;next=tp;</span><br><span class="line">    </span><br><span class="line">    tp-&gt;pagetable=<span class="keyword">new</span> <span class="keyword">int</span>[tp-&gt;size];</span><br><span class="line">    <span class="keyword">int</span> cnt,i=<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">while</span> (cnt&lt;<span class="number">64</span>)&#123;</span><br><span class="line">        <span class="keyword">if</span>(bitMap.bitmap[cnt]==<span class="number">0</span>)&#123;</span><br><span class="line">            bitMap.bitmap[cnt]=<span class="number">1</span>;</span><br><span class="line">            bitMap.<span class="built_in">free</span>--;</span><br><span class="line">            tp-&gt;pagetable[i]=cnt;</span><br><span class="line">            i++;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(i==tp-&gt;size) <span class="keyword">break</span>;</span><br><span class="line">        cnt++;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt;<span class="string">&quot;作业已装入，页表如下:&quot;</span> &lt;&lt; <span class="built_in">endl</span> &lt;&lt; <span class="string">&quot;页号\t&quot;</span> &lt;&lt; <span class="string">&quot;分配块号\t&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;tp-&gt;size;++j)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; j+<span class="number">1</span> &lt;&lt;<span class="string">&quot;\t&quot;</span> &lt;&lt; tp-&gt;pagetable[j] &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    &#125;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">void</span> <span class="title">delProc</span><span class="params">(proc *head)</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> delNum;</span><br><span class="line">    proc *tp=<span class="keyword">new</span> proc();</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;输入回收作业号&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cin</span> &gt;&gt; delNum;</span><br><span class="line">    <span class="keyword">int</span> size=tp-&gt;size;</span><br><span class="line">    <span class="keyword">if</span>(delNum==<span class="number">0</span>)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;0号作业无法删除&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span>(tp=head;tp!=<span class="literal">nullptr</span>;tp=tp-&gt;next)&#123;</span><br><span class="line">        <span class="keyword">if</span>(tp-&gt;num==delNum)&#123;</span><br><span class="line">           <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;tp-&gt;size;++j)&#123;</span><br><span class="line">               bitMap.bitmap[tp-&gt;pagetable[j]]=<span class="number">1</span>;</span><br><span class="line">               bitMap.<span class="built_in">free</span>++;</span><br><span class="line">           &#125;</span><br><span class="line">           <span class="keyword">if</span>(tp-&gt;pre!=<span class="literal">nullptr</span>)&#123;</span><br><span class="line">               <span class="keyword">if</span>(tp-&gt;next!=<span class="literal">nullptr</span>)&#123;</span><br><span class="line">                   tp-&gt;pre-&gt;next=tp-&gt;next;</span><br><span class="line">                   tp-&gt;next-&gt;pre=tp-&gt;pre;</span><br><span class="line">                   <span class="keyword">delete</span> tp;</span><br><span class="line">               &#125;</span><br><span class="line">               <span class="keyword">else</span>&#123;</span><br><span class="line">                   tp-&gt;pre-&gt;next=<span class="literal">nullptr</span>;</span><br><span class="line">                   <span class="keyword">delete</span> tp;</span><br><span class="line">               &#125;</span><br><span class="line">           &#125;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;已回收序号为&quot;</span> &lt;&lt; delNum &lt;&lt; <span class="string">&quot;的作业&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;作业大小为&quot;</span> &lt;&lt; size &lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;完成回收，返回&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;未找到作业，返回&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">return</span> ;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">void</span> <span class="title">showBitmap</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;-----------------------&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;当前位示图如下:&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;-----------------------&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">int</span> cnt=<span class="number">0</span>;</span><br><span class="line">    <span class="keyword">while</span>(cnt&lt;<span class="number">64</span>)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; bitMap.bitmap[cnt] &lt;&lt;<span class="string">&#x27;\t&#x27;</span> &lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">if</span>(cnt%<span class="number">8</span>==<span class="number">0</span>) <span class="built_in">cout</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    &#125;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">void</span> <span class="title">showPagetable</span><span class="params">(proc *head)</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> shownum;</span><br><span class="line">    proc *tp=<span class="keyword">new</span> proc();</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;-----------------------&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;输入要查看页表的作业序号&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cin</span> &gt;&gt; shownum;</span><br><span class="line">    <span class="keyword">if</span>(!shownum)&#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;无法查看0号作业，返回&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span>(tp=head;tp!=<span class="literal">nullptr</span>;tp=tp-&gt;next)&#123;</span><br><span class="line">        <span class="keyword">if</span>(tp-&gt;num=shownum)&#123;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;序号为&quot;</span> &lt;&lt;shownum &lt;&lt;<span class="string">&quot;作业页表为:&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;页号\t&quot;</span> &lt;&lt; <span class="string">&quot;块号&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;tp-&gt;size;++i)&#123;</span><br><span class="line">                <span class="built_in">cout</span> &lt;&lt; i+<span class="number">1</span> &lt;&lt;<span class="string">&quot;\t&quot;</span> &lt;&lt; tp-&gt;pagetable[i] &lt;&lt; <span class="string">&quot;\t&quot;</span> &lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;序号为&quot;</span> &lt;&lt; shownum &lt;&lt;<span class="string">&quot;作业展示结束&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;-----------------------&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;未找到作业号&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">    bitMap.bitmap[<span class="number">0</span>]=bitMap.bitmap[<span class="number">1</span>]=bitMap.bitmap[<span class="number">4</span>]=bitMap.bitmap[<span class="number">5</span>]=bitMap.bitmap[<span class="number">6</span>]=</span><br><span class="line">    bitMap.bitmap[<span class="number">9</span>]=bitMap.bitmap[<span class="number">11</span>]=bitMap.bitmap[<span class="number">13</span>]=bitMap.bitmap[<span class="number">24</span>]=bitMap.bitmap[<span class="number">31</span>]=<span class="number">1</span>;</span><br><span class="line">    bitMap.<span class="built_in">free</span>=<span class="number">64</span>;</span><br><span class="line">    proc *head=<span class="keyword">new</span> proc();</span><br><span class="line">    head-&gt;next=<span class="literal">nullptr</span>;</span><br><span class="line">    head-&gt;pre=<span class="literal">nullptr</span>;</span><br><span class="line">    head-&gt;num=<span class="number">0</span>;</span><br><span class="line">    head-&gt;size=<span class="number">6</span>;</span><br><span class="line">    head-&gt;pagetable=<span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">6</span>];</span><br><span class="line">    head-&gt;pagetable[<span class="number">0</span>]=<span class="number">0</span>;</span><br><span class="line">    head-&gt;pagetable[<span class="number">1</span>]=<span class="number">1</span>;</span><br><span class="line">    head-&gt;pagetable[<span class="number">2</span>]=<span class="number">9</span>;</span><br><span class="line">    head-&gt;pagetable[<span class="number">3</span>]=<span class="number">11</span>;</span><br><span class="line">    head-&gt;pagetable[<span class="number">4</span>]=<span class="number">13</span>;</span><br><span class="line">    head-&gt;pagetable[<span class="number">5</span>]=<span class="number">24</span>;</span><br><span class="line"></span><br><span class="line">    proc *prc1=<span class="keyword">new</span> proc();</span><br><span class="line">    head-&gt;next=prc1;</span><br><span class="line">    prc1-&gt;pre=head;</span><br><span class="line">    prc1-&gt;next=<span class="literal">nullptr</span>;</span><br><span class="line">    prc1-&gt;num=<span class="number">1</span>;</span><br><span class="line">    prc1-&gt;size=<span class="number">4</span>;</span><br><span class="line">    prc1-&gt;pagetable=<span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">4</span>];</span><br><span class="line">    prc1-&gt;pagetable[<span class="number">0</span>]=<span class="number">4</span>;</span><br><span class="line">    prc1-&gt;pagetable[<span class="number">1</span>]=<span class="number">5</span>;</span><br><span class="line">    prc1-&gt;pagetable[<span class="number">2</span>]=<span class="number">6</span>;</span><br><span class="line">    prc1-&gt;pagetable[<span class="number">3</span>]=<span class="number">31</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">char</span> ch;</span><br><span class="line">    <span class="keyword">while</span>(<span class="literal">true</span>)&#123;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;-----------操作列表-----------&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;1.创建新作业，并请求内存空间&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;2.回收作业，并返回内存&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;3.展示位示图&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;4.展示进程页表&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">        <span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;0.退出&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;请输入序号:&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">        <span class="built_in">cout</span>&lt;&lt;<span class="string">&quot;-------------------------&quot;</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line">        <span class="built_in">cin</span>&gt;&gt;ch;</span><br><span class="line">        <span class="keyword">switch</span> (ch)&#123;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">&#x27;0&#x27;</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">&#x27;1&#x27;</span>:</span><br><span class="line">            creProc(head);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">&#x27;2&#x27;</span>:</span><br><span class="line">            delProc(head);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">&#x27;3&#x27;</span>:</span><br><span class="line">            showBitmap();</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">&#x27;4&#x27;</span>:</span><br><span class="line">            showPagetable(head);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">default</span>:</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;输入错误&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


    </div>
    
    
    

      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/C/" rel="tag"><i class="fa fa-tag"></i> C++</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/12/15/linux-memModel-memMap/" rel="prev" title="Linux下地址映射机制">
      <i class="fa fa-chevron-left"></i> Linux下地址映射机制
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/12/16/os-schoollab-8/" rel="next" title="MS-DOS文件储存模拟">
      MS-DOS文件储存模拟 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#LRU%E7%AE%97%E6%B3%95%E5%AE%9E%E7%8E%B0"><span class="nav-number">1.</span> <span class="nav-text">LRU算法实现</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%BB%E5%AD%98%E5%82%A8%E7%A9%BA%E9%97%B4%E7%9A%84%E5%88%86%E9%85%8D%E4%B8%8E%E5%9B%9E%E6%94%B6"><span class="nav-number">2.</span> <span class="nav-text">主存储空间的分配与回收</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8F%AF%E5%8F%98%E5%88%86%E5%8C%BA%E7%AE%A1%E7%90%86%E4%B8%8B%E9%87%87%E7%94%A8%E6%9C%80%E5%85%88%E9%80%82%E5%BA%94%E7%AE%97%E6%B3%95%E5%AE%9E%E7%8E%B0%E4%B8%BB%E5%AD%98%E5%88%86%E9%85%8D%E5%92%8C%E5%9B%9E%E6%94%B6"><span class="nav-number">2.1.</span> <span class="nav-text">可变分区管理下采用最先适应算法实现主存分配和回收</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%8D%E5%9B%BE%E7%BB%B4%E6%8A%A4%E5%86%85%E5%AD%98"><span class="nav-number">2.2.</span> <span class="nav-text">位图维护内存</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Sekla"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Sekla</p>
  <div class="site-description" itemprop="description">Sekla</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">100</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/ShenTiao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;ShenTiao" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:584892986@qq.com" title="E-Mail → mailto:584892986@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

      <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=1416875904&auto=0&height=66"></iframe>
      
    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Sekla</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">288k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">4:22</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script size="300" alpha="0.6" zIndex="-1" src="/lib/canvas-ribbon/canvas-ribbon.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":250,"height":500},"mobile":{"show":false},"react":{"opacity":0.9},"log":false});</script></body>
</html>

<script type="text/javascript" src="/js/src/love.js"></script>
